﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Databasic.Api.Wrter.Controllers
{
    /// <summary>
    /// 上传控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ImgController : ControllerBase
    {
        private readonly IWebHostEnvironment web;

        public ImgController(IWebHostEnvironment web)
        {
            this.web = web;
        }
        [HttpPost]
        public IActionResult UploadImg(IFormFile file)
        {
            string n = Guid.NewGuid().ToString();
            string path = web.WebRootPath + "/Upload/" + n + file.FileName;
            using (FileStream fs = System.IO.File.Create(path))
            {
                file.CopyTo(fs);
                fs.Close();
            }
            return Ok("http://localhost:5013" + "/Upload/" + n + file.FileName);
        }
    }
}
